﻿var CurrentUser = {};

Ext.onReady(function () {
    PageSafe();

    var personstore = new Ext.data.JsonStore({
        url: Ext.getClassUrl('BaseManager.PersonManager.PersonView', 'GetPersonList'),
        root: 'ResponseObject',
        fields: ['PID', 'UserAccount', 'UserName', 'ChargeArea.AreaName', 'Company', 'Tel', 'Email', 'Age', 'NTime', 'UserInto', 'Job'],
        listeners: {
            beforeload: function (st, op) {
                var re = new JsonRequest();
                re.category = CATEGORY.READONLY;
                st.baseParams = re;
                st.proxy.conn.jsonData = re;
            }
        }
    });
    var personsm = new Ext.grid.CheckboxSelectionModel({
        singleSelect: true,
        listeners: {
            rowselect: function () {
                var k = persongrid.getSelectionModel().selections.items;
                if (k.length > 0) {
                    CurrentUser = k[0].json;
                }
            }
        }
    });
    var persongrid = new Ext.grid.GridPanel({
        bodyStyle: 'padding:2px',
        border: false,
        split: true,
        height: 500,
        sm: personsm,
        loadMask: true, //加载
        columns: [
       personsm,
       { id: 'UserAccount', header: '用户名', width: 100, dataIndex: 'UserAccount', sortable: true },
       { id: 'UserName', header: '用户姓名', width: 100, dataIndex: 'UserName', sortable: true },
       { id: 'ChargeArea.AreaName', header: '所属地区', width: 200, dataIndex: 'ChargeArea.AreaName', sortable: true },
       { id: 'Company', header: '公司名称', width: 100, dataIndex: 'Company', sortable: true },
       { id: 'Tel', header: '联系电话', width: 100, dataIndex: 'Tel', sortable: true },
       { id: 'Email', header: '电子邮箱', width: 100, dataIndex: 'Email', sortable: true },
       { id: 'Age', header: '年龄', width: 100, dataIndex: 'Age', sortable: true },
       { id: 'Job', header: '职称', width: 100, dataIndex: 'Job', sortable: true },
       { id: 'UserInto', header: '分成比例', width: 100, dataIndex: 'UserInto', sortable: true },
       { id: 'NTime', header: '注册时间', width: 100, dataIndex: 'NTime', sortable: true }
   ],
        store: personstore
    });


    var winpage = new Ext.Viewport({
        layout: 'border',
        items: [{
            region: 'center',
            title: '人员密码恢复',
            tbar: [{ text: '恢复初始密码', iconCls: 'reflash-icon', handler: function () {
                if (CurrentUser.PID == null) { Ext.Msg.alert("提示信息", "请选择一个人员恢复密码"); return; }
                var re = new JsonRequest();
                re.params.UserInfo = CurrentUser;
                Ext.Ajax.request({
                    url: Ext.getClassUrl('BaseManager.PersonManager.PersonView', 'InitPass'),
                    jsonData: re,
                    success: function (re, op) {
                        var obj = Ext.decode(re.responseText);
                        if (obj.ResponseObject != null) {
                            Ext.Msg.alert("提示信息", "用户[" + CurrentUser.UserName + "]密码恢复初始成功，密码为123456");
                        }
                        else {
                            Ext.Msg.alert("提示信息", "用户密码恢复初始失败，请联系管理员");
                        }
                    }
                });
            }
            }],
            items: persongrid
        }],
        listeners: {
            render: function () {
                personstore.load();
            }
        }
    });
});